

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" href="/img/favicon.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="John Doe">
  <meta name="keywords" content="">
  
    <meta name="description" content="Traversable（遍历）接口简介检测一个类是否可以使用 foreach 进行遍历的接口。 无法被单独实现的基本抽象接口。相反它必须由 IteratorAggregate 或 Iterator 接口实现。 Note: 实现此接口的内建类可以使用 foreach 进行遍历而无需实现 IteratorAggregate 或 Iterator 接口。   Note: 这是一个无法在 PHP 脚本中实">
<meta property="og:type" content="article">
<meta property="og:title" content="PHP手册-预定义接口">
<meta property="og:url" content="http://example.com/2018/10/31/php/PHP%E6%89%8B%E5%86%8C-%E9%A2%84%E5%AE%9A%E4%B9%89%E6%8E%A5%E5%8F%A3/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="Traversable（遍历）接口简介检测一个类是否可以使用 foreach 进行遍历的接口。 无法被单独实现的基本抽象接口。相反它必须由 IteratorAggregate 或 Iterator 接口实现。 Note: 实现此接口的内建类可以使用 foreach 进行遍历而无需实现 IteratorAggregate 或 Iterator 接口。   Note: 这是一个无法在 PHP 脚本中实">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2018-10-31T06:17:59.000Z">
<meta property="article:modified_time" content="2022-02-10T03:11:43.940Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="PHP">
<meta name="twitter:card" content="summary_large_image">
  
  
  <title>PHP手册-预定义接口 - Hexo</title>

  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4/github-markdown.min.css" />
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hint.css@2/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10/styles/github-gist.min.css" />
    
  

  
    <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.css" />
  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.8.13","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 6.0.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>LZDF</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('/img/default.png') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="PHP手册-预定义接口">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2018-10-31 14:17" pubdate>
        2018年10月31日 下午
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      7.4k 字
    </span>
  

  
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      62 分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">PHP手册-预定义接口</h1>
            
            <div class="markdown-body">
              <h1 id="Traversable（遍历）接口"><a href="#Traversable（遍历）接口" class="headerlink" title="Traversable（遍历）接口"></a>Traversable（遍历）接口</h1><h2 id="简介"><a href="#简介" class="headerlink" title="简介"></a>简介</h2><p>检测一个类是否可以使用 foreach 进行遍历的接口。</p>
<p>无法被单独实现的基本抽象接口。相反它必须由 <code>IteratorAggregate</code> 或 <code>Iterator</code> 接口实现。</p>
<pre><code>Note:
实现此接口的内建类可以使用 foreach 进行遍历而无需实现 IteratorAggregate 或 Iterator 接口。
</code></pre>
<hr>
<pre><code>Note:
这是一个无法在 PHP 脚本中实现的内部引擎接口。IteratorAggregate 或 Iterator 接口可以用来代替它。
</code></pre>
<h2 id="接口摘要"><a href="#接口摘要" class="headerlink" title="接口摘要"></a>接口摘要</h2><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs php"><span class="hljs-built_in">Traversable</span> &#123;<br>&#125;<br></code></pre></td></tr></table></figure>
<p>这个接口没有任何方法，它的作用仅仅是作为所有可遍历类的基本接口。</p>
<h2 id="范例"><a href="#范例" class="headerlink" title="范例"></a>范例</h2><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs php"><span class="hljs-meta">&lt;?php</span><br><span class="hljs-variable">$myarray</span> = <span class="hljs-keyword">array</span>(<span class="hljs-string">&#x27;one&#x27;</span>, <span class="hljs-string">&#x27;two&#x27;</span>, <span class="hljs-string">&#x27;three&#x27;</span>);<br><span class="hljs-variable">$myobj</span> = (<span class="hljs-keyword">object</span>)<span class="hljs-variable">$myarray</span>;<br><br><span class="hljs-keyword">if</span> ( !(<span class="hljs-variable">$myarray</span> <span class="hljs-keyword">instanceof</span> \<span class="hljs-built_in">Traversable</span>) ) &#123;<br>    <span class="hljs-keyword">print</span> <span class="hljs-string">&quot;myarray is NOT Traversable&quot;</span>;<br>&#125;<br><span class="hljs-keyword">if</span> ( !(<span class="hljs-variable">$myobj</span> <span class="hljs-keyword">instanceof</span> \<span class="hljs-built_in">Traversable</span>) ) &#123;<br>    <span class="hljs-keyword">print</span> <span class="hljs-string">&quot;myobj is NOT Traversable&quot;</span>;<br>&#125;<br><br><span class="hljs-keyword">foreach</span> (<span class="hljs-variable">$myarray</span> <span class="hljs-keyword">as</span> <span class="hljs-variable">$value</span>) &#123;<br>    <span class="hljs-keyword">print</span> <span class="hljs-variable">$value</span>;<br>&#125;<br><span class="hljs-keyword">foreach</span> (<span class="hljs-variable">$myobj</span> <span class="hljs-keyword">as</span> <span class="hljs-variable">$value</span>) &#123;<br>    <span class="hljs-keyword">print</span> <span class="hljs-variable">$value</span>;<br>&#125;<br></code></pre></td></tr></table></figure>
<p>上面的例子大概会输出：</p>
<pre><code>myarray is NOT Traversable
myobj is NOT Traversable
one
two
three
one
two
three
</code></pre>
<h1 id="Iterator（迭代器）接口"><a href="#Iterator（迭代器）接口" class="headerlink" title="Iterator（迭代器）接口"></a>Iterator（迭代器）接口</h1><h2 id="简介-1"><a href="#简介-1" class="headerlink" title="简介"></a>简介</h2><p>可在内部迭代自己的外部迭代器或类的接口。</p>
<h2 id="接口摘要-1"><a href="#接口摘要-1" class="headerlink" title="接口摘要"></a>接口摘要</h2><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs php"><span class="hljs-built_in">Iterator</span> <span class="hljs-keyword">extends</span> <span class="hljs-built_in">Traversable</span> &#123;<br><span class="hljs-comment">/* 方法 */</span><br><span class="hljs-keyword">abstract</span> <span class="hljs-keyword">public</span> <span class="hljs-keyword">mixed</span> current ( <span class="hljs-keyword">void</span> )<br><span class="hljs-keyword">abstract</span> <span class="hljs-keyword">public</span> scalar key ( <span class="hljs-keyword">void</span> )<br><span class="hljs-keyword">abstract</span> <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> next ( <span class="hljs-keyword">void</span> )<br><span class="hljs-keyword">abstract</span> <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> rewind ( <span class="hljs-keyword">void</span> )<br><span class="hljs-keyword">abstract</span> <span class="hljs-keyword">public</span> <span class="hljs-keyword">bool</span> valid ( <span class="hljs-keyword">void</span> )<br>&#125;<br></code></pre></td></tr></table></figure>

<h2 id="预定义迭代器"><a href="#预定义迭代器" class="headerlink" title="预定义迭代器"></a>预定义迭代器</h2><p>PHP 已经提供了一些用于日常任务的迭代器。 详细列表参见 <a target="_blank" rel="noopener" href="http://php.net/manual/zh/spl.iterators.php">SPL 迭代器</a>。</p>
<h2 id="范例-1"><a href="#范例-1" class="headerlink" title="范例"></a>范例</h2><p>这个例子展示了使用 foreach 时，迭代器方法的调用顺序。</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><code class="hljs php"><span class="hljs-meta">&lt;?php</span><br><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">myIterator</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">Iterator</span> </span>&#123;<br>    <span class="hljs-keyword">private</span> <span class="hljs-variable">$position</span> = <span class="hljs-number">0</span>;<br>    <span class="hljs-keyword">private</span> <span class="hljs-variable">$array</span> = <span class="hljs-keyword">array</span>(<br>        <span class="hljs-string">&quot;firstelement&quot;</span>,<br>        <span class="hljs-string">&quot;secondelement&quot;</span>,<br>        <span class="hljs-string">&quot;lastelement&quot;</span>,<br>    );  <br><br>    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">__construct</span>(<span class="hljs-params"></span>) </span>&#123;<br>        <span class="hljs-keyword">$this</span>-&gt;position = <span class="hljs-number">0</span>;<br>    &#125;<br><br>    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">rewind</span>(<span class="hljs-params"></span>) </span>&#123;<br>        var_dump(<span class="hljs-keyword">__METHOD__</span>);<br>        <span class="hljs-keyword">$this</span>-&gt;position = <span class="hljs-number">0</span>;<br>    &#125;<br><br>    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">current</span>(<span class="hljs-params"></span>) </span>&#123;<br>        var_dump(<span class="hljs-keyword">__METHOD__</span>);<br>        <span class="hljs-keyword">return</span> <span class="hljs-keyword">$this</span>-&gt;array[<span class="hljs-keyword">$this</span>-&gt;position];<br>    &#125;<br><br>    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">key</span>(<span class="hljs-params"></span>) </span>&#123;<br>        var_dump(<span class="hljs-keyword">__METHOD__</span>);<br>        <span class="hljs-keyword">return</span> <span class="hljs-keyword">$this</span>-&gt;position;<br>    &#125;<br><br>    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">next</span>(<span class="hljs-params"></span>) </span>&#123;<br>        var_dump(<span class="hljs-keyword">__METHOD__</span>);<br>        ++<span class="hljs-keyword">$this</span>-&gt;position;<br>    &#125;<br><br>    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">valid</span>(<span class="hljs-params"></span>) </span>&#123;<br>        var_dump(<span class="hljs-keyword">__METHOD__</span>);<br>        <span class="hljs-keyword">return</span> <span class="hljs-keyword">isset</span>(<span class="hljs-keyword">$this</span>-&gt;array[<span class="hljs-keyword">$this</span>-&gt;position]);<br>    &#125;<br>&#125;<br><br><span class="hljs-variable">$it</span> = <span class="hljs-keyword">new</span> myIterator;<br><br><span class="hljs-keyword">foreach</span>(<span class="hljs-variable">$it</span> <span class="hljs-keyword">as</span> <span class="hljs-variable">$key</span> =&gt; <span class="hljs-variable">$value</span>) &#123;<br>    var_dump(<span class="hljs-variable">$key</span>, <span class="hljs-variable">$value</span>);<br>    <span class="hljs-keyword">echo</span> <span class="hljs-string">&quot;\n&quot;</span>;<br>&#125;<br></code></pre></td></tr></table></figure>
<p>以上例程的输出类似于：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><code class="hljs bash">string(18) <span class="hljs-string">&quot;myIterator::rewind&quot;</span><br>string(17) <span class="hljs-string">&quot;myIterator::valid&quot;</span><br>string(19) <span class="hljs-string">&quot;myIterator::current&quot;</span><br>string(15) <span class="hljs-string">&quot;myIterator::key&quot;</span><br>int(0)<br>string(12) <span class="hljs-string">&quot;firstelement&quot;</span><br><br>string(16) <span class="hljs-string">&quot;myIterator::next&quot;</span><br>string(17) <span class="hljs-string">&quot;myIterator::valid&quot;</span><br>string(19) <span class="hljs-string">&quot;myIterator::current&quot;</span><br>string(15) <span class="hljs-string">&quot;myIterator::key&quot;</span><br>int(1)<br>string(13) <span class="hljs-string">&quot;secondelement&quot;</span><br><br>string(16) <span class="hljs-string">&quot;myIterator::next&quot;</span><br>string(17) <span class="hljs-string">&quot;myIterator::valid&quot;</span><br>string(19) <span class="hljs-string">&quot;myIterator::current&quot;</span><br>string(15) <span class="hljs-string">&quot;myIterator::key&quot;</span><br>int(2)<br>string(11) <span class="hljs-string">&quot;lastelement&quot;</span><br><br>string(16) <span class="hljs-string">&quot;myIterator::next&quot;</span><br>string(17) <span class="hljs-string">&quot;myIterator::valid&quot;</span><br></code></pre></td></tr></table></figure>
<h2 id="Table-of-Contents"><a href="#Table-of-Contents" class="headerlink" title="Table of Contents"></a>Table of Contents</h2><ul>
<li>Iterator::current — 返回当前元素</li>
<li>Iterator::key — 返回当前元素的键</li>
<li>Iterator::next — 向前移动到下一个元素</li>
<li>Iterator::rewind — 返回到迭代器的第一个元素</li>
<li>Iterator::valid — 检查当前位置是否有效</li>
</ul>
<p><em><a target="_blank" rel="noopener" href="https://segmentfault.com/q/1010000010830185">php 迭代接口的作用</a></em></p>
<h1 id="IteratorAggregate（聚合式迭代器）接口"><a href="#IteratorAggregate（聚合式迭代器）接口" class="headerlink" title="IteratorAggregate（聚合式迭代器）接口"></a>IteratorAggregate（聚合式迭代器）接口</h1><h2 id="简介-2"><a href="#简介-2" class="headerlink" title="简介"></a>简介</h2><p>创建外部迭代器的接口。</p>
<h2 id="接口摘要-2"><a href="#接口摘要-2" class="headerlink" title="接口摘要"></a>接口摘要</h2><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs php"><span class="hljs-built_in">IteratorAggregate</span> <span class="hljs-keyword">extends</span> <span class="hljs-built_in">Traversable</span> &#123;<br><span class="hljs-comment">/* 方法 */</span><br><span class="hljs-keyword">abstract</span> <span class="hljs-keyword">public</span> <span class="hljs-built_in">Traversable</span> getIterator ( <span class="hljs-keyword">void</span> )    <span class="hljs-comment">// 获取一个外部迭代器</span><br>&#125;<br></code></pre></td></tr></table></figure>
<h3 id="Example-1-基本用法"><a href="#Example-1-基本用法" class="headerlink" title="Example #1 基本用法"></a>Example #1 基本用法</h3><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><code class="hljs php"><span class="hljs-meta">&lt;?php</span><br><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">myData</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">IteratorAggregate</span> </span>&#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-variable">$property1</span> = <span class="hljs-string">&quot;Public property one&quot;</span>;<br>    <span class="hljs-keyword">public</span> <span class="hljs-variable">$property2</span> = <span class="hljs-string">&quot;Public property two&quot;</span>;<br>    <span class="hljs-keyword">public</span> <span class="hljs-variable">$property3</span> = <span class="hljs-string">&quot;Public property three&quot;</span>;<br><br>    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">__construct</span>(<span class="hljs-params"></span>) </span>&#123;<br>        <span class="hljs-keyword">$this</span>-&gt;property4 = <span class="hljs-string">&quot;last property&quot;</span>;<br>    &#125;<br><br>    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getIterator</span>(<span class="hljs-params"></span>) </span>&#123;<br>        <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">ArrayIterator</span>(<span class="hljs-keyword">$this</span>);<br>    &#125;<br>&#125;<br><br><span class="hljs-variable">$obj</span> = <span class="hljs-keyword">new</span> myData;<br><br><span class="hljs-keyword">foreach</span>(<span class="hljs-variable">$obj</span> <span class="hljs-keyword">as</span> <span class="hljs-variable">$key</span> =&gt; <span class="hljs-variable">$value</span>) &#123;<br>    var_dump(<span class="hljs-variable">$key</span>, <span class="hljs-variable">$value</span>);<br>    <span class="hljs-keyword">echo</span> <span class="hljs-string">&quot;\n&quot;</span>;<br>&#125;<br></code></pre></td></tr></table></figure>
<p>以上例程的输出类似于：</p>
<pre><code>string(9) &quot;property1&quot;
string(19) &quot;Public property one&quot;

string(9) &quot;property2&quot;
string(19) &quot;Public property two&quot;

string(9) &quot;property3&quot;
string(21) &quot;Public property three&quot;

string(9) &quot;property4&quot;
string(13) &quot;last property&quot;
</code></pre>
<h1 id="ArrayAccess（数组式访问）接口"><a href="#ArrayAccess（数组式访问）接口" class="headerlink" title="ArrayAccess（数组式访问）接口"></a>ArrayAccess（数组式访问）接口</h1><h2 id="简介-3"><a href="#简介-3" class="headerlink" title="简介"></a>简介</h2><p>提供像<strong>访问数组一样访问对象</strong>的能力的接口。</p>
<h2 id="接口摘要-3"><a href="#接口摘要-3" class="headerlink" title="接口摘要"></a>接口摘要</h2><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs php"><span class="hljs-built_in">ArrayAccess</span> &#123;<br><span class="hljs-comment">/* 方法 */</span><br><span class="hljs-keyword">abstract</span> <span class="hljs-keyword">public</span> <span class="hljs-keyword">boolean</span> offsetExists ( <span class="hljs-keyword">mixed</span> <span class="hljs-variable">$offset</span> )<br><span class="hljs-keyword">abstract</span> <span class="hljs-keyword">public</span> <span class="hljs-keyword">mixed</span> offsetGet ( <span class="hljs-keyword">mixed</span> <span class="hljs-variable">$offset</span> )<br><span class="hljs-keyword">abstract</span> <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> offsetSet ( <span class="hljs-keyword">mixed</span> <span class="hljs-variable">$offset</span> , <span class="hljs-keyword">mixed</span> <span class="hljs-variable">$value</span> )<br><span class="hljs-keyword">abstract</span> <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> offsetUnset ( <span class="hljs-keyword">mixed</span> <span class="hljs-variable">$offset</span> )<br>&#125;<br></code></pre></td></tr></table></figure>
<h2 id="Example-1-Basic-usage"><a href="#Example-1-Basic-usage" class="headerlink" title="Example #1 Basic usage"></a>Example #1 Basic usage</h2><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><code class="hljs php"><span class="hljs-meta">&lt;?php</span><br><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">obj</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">arrayaccess</span> </span>&#123;<br>    <span class="hljs-keyword">private</span> <span class="hljs-variable">$container</span> = <span class="hljs-keyword">array</span>();<br>    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">__construct</span>(<span class="hljs-params"></span>) </span>&#123;<br>        <span class="hljs-keyword">$this</span>-&gt;container = <span class="hljs-keyword">array</span>(<br>            <span class="hljs-string">&quot;one&quot;</span>   =&gt; <span class="hljs-number">1</span>,<br>            <span class="hljs-string">&quot;two&quot;</span>   =&gt; <span class="hljs-number">2</span>,<br>            <span class="hljs-string">&quot;three&quot;</span> =&gt; <span class="hljs-number">3</span>,<br>        );<br>    &#125;<br>    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">offsetSet</span>(<span class="hljs-params"><span class="hljs-variable">$offset</span>, <span class="hljs-variable">$value</span></span>) </span>&#123;<br>        <span class="hljs-keyword">if</span> (is_null(<span class="hljs-variable">$offset</span>)) &#123;<br>            <span class="hljs-keyword">$this</span>-&gt;container[] = <span class="hljs-variable">$value</span>;<br>        &#125; <span class="hljs-keyword">else</span> &#123;<br>            <span class="hljs-keyword">$this</span>-&gt;container[<span class="hljs-variable">$offset</span>] = <span class="hljs-variable">$value</span>;<br>        &#125;<br>    &#125;<br>    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">offsetExists</span>(<span class="hljs-params"><span class="hljs-variable">$offset</span></span>) </span>&#123;<br>        <span class="hljs-keyword">return</span> <span class="hljs-keyword">isset</span>(<span class="hljs-keyword">$this</span>-&gt;container[<span class="hljs-variable">$offset</span>]);<br>    &#125;<br>    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">offsetUnset</span>(<span class="hljs-params"><span class="hljs-variable">$offset</span></span>) </span>&#123;<br>        <span class="hljs-keyword">unset</span>(<span class="hljs-keyword">$this</span>-&gt;container[<span class="hljs-variable">$offset</span>]);<br>    &#125;<br>    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">offsetGet</span>(<span class="hljs-params"><span class="hljs-variable">$offset</span></span>) </span>&#123;<br>        <span class="hljs-keyword">return</span> <span class="hljs-keyword">isset</span>(<span class="hljs-keyword">$this</span>-&gt;container[<span class="hljs-variable">$offset</span>]) ? <span class="hljs-keyword">$this</span>-&gt;container[<span class="hljs-variable">$offset</span>] : <span class="hljs-literal">null</span>;<br>    &#125;<br>&#125;<br><br><span class="hljs-variable">$obj</span> = <span class="hljs-keyword">new</span> obj;<br><br>var_dump(<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$obj</span>[<span class="hljs-string">&quot;two&quot;</span>]));<br>var_dump(<span class="hljs-variable">$obj</span>[<span class="hljs-string">&quot;two&quot;</span>]);<br><span class="hljs-keyword">unset</span>(<span class="hljs-variable">$obj</span>[<span class="hljs-string">&quot;two&quot;</span>]);<br>var_dump(<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$obj</span>[<span class="hljs-string">&quot;two&quot;</span>]));<br><span class="hljs-variable">$obj</span>[<span class="hljs-string">&quot;two&quot;</span>] = <span class="hljs-string">&quot;A value&quot;</span>;<br>var_dump(<span class="hljs-variable">$obj</span>[<span class="hljs-string">&quot;two&quot;</span>]);<br><span class="hljs-variable">$obj</span>[] = <span class="hljs-string">&#x27;Append 1&#x27;</span>;<br><span class="hljs-variable">$obj</span>[] = <span class="hljs-string">&#x27;Append 2&#x27;</span>;<br><span class="hljs-variable">$obj</span>[] = <span class="hljs-string">&#x27;Append 3&#x27;</span>;<br>print_r(<span class="hljs-variable">$obj</span>);<br></code></pre></td></tr></table></figure>
<p>以上例程的输出类似于：</p>
<pre><code>bool(true)
int(2)
bool(false)
string(7) &quot;A value&quot;
obj Object
(
    [container:obj:private] =&gt; Array
        (
            [one] =&gt; 1
            [three] =&gt; 3
            [two] =&gt; A value
            [0] =&gt; Append 1
            [1] =&gt; Append 2
            [2] =&gt; Append 3
        )

)
</code></pre>
<h2 id="Table-of-Contents-¶"><a href="#Table-of-Contents-¶" class="headerlink" title="Table of Contents ¶"></a>Table of Contents ¶</h2><ul>
<li>ArrayAccess::offsetExists — 检查一个偏移位置是否存在</li>
<li>ArrayAccess::offsetGet — 获取一个偏移位置的值</li>
<li>ArrayAccess::offsetSet — 设置一个偏移位置的值</li>
<li>ArrayAccess::offsetUnset — 复位一个偏移位置的值</li>
</ul>
<h1 id="序列化接口"><a href="#序列化接口" class="headerlink" title="序列化接口"></a>序列化接口</h1><h2 id="简介-4"><a href="#简介-4" class="headerlink" title="简介"></a>简介</h2><p>自定义序列化的接口。</p>
<p>实现此接口的类将不再支持 __sleep() 和 __wakeup()。不论何时，只要有实例需要被序列化，serialize 方法都将被调用。它将不会调用 __destruct() 或有其他影响，除非程序化地调用此方法。当数据被反序列化时，类将被感知并且调用合适的 unserialize() 方法而不是调用 __construct()。如果需要执行标准的构造器，你应该在这个方法中进行处理。</p>
<h2 id="接口摘要-4"><a href="#接口摘要-4" class="headerlink" title="接口摘要"></a>接口摘要</h2><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs php"><span class="hljs-built_in">Serializable</span> &#123;<br><span class="hljs-comment">/* 方法 */</span><br><span class="hljs-keyword">abstract</span> <span class="hljs-keyword">public</span> <span class="hljs-keyword">string</span> serialize ( <span class="hljs-keyword">void</span> )<br><span class="hljs-keyword">abstract</span> <span class="hljs-keyword">public</span> <span class="hljs-keyword">mixed</span> unserialize ( <span class="hljs-keyword">string</span> <span class="hljs-variable">$serialized</span> )<br>&#125;<br></code></pre></td></tr></table></figure>
<h2 id="Example-1-Basic-usage-1"><a href="#Example-1-Basic-usage-1" class="headerlink" title="Example #1 Basic usage"></a>Example #1 Basic usage</h2><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><code class="hljs php"><span class="hljs-meta">&lt;?php</span><br><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">obj</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">Serializable</span> </span>&#123;<br>    <span class="hljs-keyword">private</span> <span class="hljs-variable">$data</span>;<br>    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">__construct</span>(<span class="hljs-params"></span>) </span>&#123;<br>        <span class="hljs-keyword">$this</span>-&gt;data = <span class="hljs-string">&quot;My private data&quot;</span>;<br>    &#125;<br>    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">serialize</span>(<span class="hljs-params"></span>) </span>&#123;<br>        <span class="hljs-keyword">return</span> serialize(<span class="hljs-keyword">$this</span>-&gt;data);<br>    &#125;<br>    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">unserialize</span>(<span class="hljs-params"><span class="hljs-variable">$data</span></span>) </span>&#123;<br>        <span class="hljs-keyword">$this</span>-&gt;data = unserialize(<span class="hljs-variable">$data</span>);<br>    &#125;<br>    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getData</span>(<span class="hljs-params"></span>) </span>&#123;<br>        <span class="hljs-keyword">return</span> <span class="hljs-keyword">$this</span>-&gt;data;<br>    &#125;<br>&#125;<br><br><span class="hljs-variable">$obj</span> = <span class="hljs-keyword">new</span> obj;<br><span class="hljs-variable">$ser</span> = serialize(<span class="hljs-variable">$obj</span>);<br><br><span class="hljs-variable">$newobj</span> = unserialize(<span class="hljs-variable">$ser</span>);<br><br>var_dump(<span class="hljs-variable">$newobj</span>-&gt;getData());<br></code></pre></td></tr></table></figure>
<p>以上例程的输出类似于：</p>
<pre><code>string(15) &quot;My private data&quot;
</code></pre>
<h2 id="Table-of-Contents-1"><a href="#Table-of-Contents-1" class="headerlink" title="Table of Contents"></a>Table of Contents</h2><ul>
<li>Serializable::serialize — 对象的字符串表示</li>
<li>Serializable::unserialize — 构造对象</li>
</ul>
<h1 id="Closure-类"><a href="#Closure-类" class="headerlink" title="Closure 类"></a>Closure 类</h1><h2 id="简介-5"><a href="#简介-5" class="headerlink" title="简介"></a>简介</h2><p>用于代表 匿名函数 的类.</p>
<p>匿名函数（在 PHP 5.3 中被引入）会产生这个类型的对象。在过去，这个类被认为是一个实现细节，但现在可以依赖它做一些事情。自 PHP 5.4 起，这个类带有一些方法，允许在匿名函数创建后对其进行更多的控制。</p>
<p>除了此处列出的方法，还有一个 __invoke 方法。这是为了与其他实现了 __invoke()魔术方法 的对象保持一致性，但调用匿名函数的过程与它无关。</p>
<h2 id="类摘要"><a href="#类摘要" class="headerlink" title="类摘要"></a>类摘要</h2><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs php"><span class="hljs-built_in">Closure</span> &#123;<br>    <span class="hljs-comment">/* 方法 */</span><br>    __construct ( <span class="hljs-keyword">void</span> )<br>    <span class="hljs-keyword">public</span> <span class="hljs-built_in">static</span> <span class="hljs-built_in">Closure</span> bind ( <span class="hljs-built_in">Closure</span> <span class="hljs-variable">$closure</span> , <span class="hljs-keyword">object</span> <span class="hljs-variable">$newthis</span> [, <span class="hljs-keyword">mixed</span> <span class="hljs-variable">$newscope</span> = <span class="hljs-string">&#x27;static&#x27;</span> ] )<br>    <span class="hljs-keyword">public</span> <span class="hljs-built_in">Closure</span> bindTo ( <span class="hljs-keyword">object</span> <span class="hljs-variable">$newthis</span> [, <span class="hljs-keyword">mixed</span> <span class="hljs-variable">$newscope</span> = <span class="hljs-string">&#x27;static&#x27;</span> ] )<br>&#125;<br></code></pre></td></tr></table></figure>
<h2 id="Table-of-Contents-2"><a href="#Table-of-Contents-2" class="headerlink" title="Table of Contents"></a>Table of Contents</h2><ul>
<li>Closure::__construct — 用于禁止实例化的构造函数</li>
<li>Closure::bind — 复制一个闭包，绑定指定的$this对象和类作用域。</li>
<li>Closure::bindTo — 复制当前闭包对象，绑定指定的$this对象和类作用域。</li>
</ul>
<h1 id="生成器类"><a href="#生成器类" class="headerlink" title="生成器类"></a>生成器类</h1><h2 id="简介-6"><a href="#简介-6" class="headerlink" title="简介"></a>简介</h2><p>Generator 对象是从 generators返回的.</p>
<pre><code>Caution Generator 对象不能通过 new 实例化.
</code></pre>
<h2 id="类摘要-1"><a href="#类摘要-1" class="headerlink" title="类摘要"></a>类摘要</h2><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs php"><span class="hljs-built_in">Generator</span> <span class="hljs-keyword">implements</span> <span class="hljs-built_in">Iterator</span> &#123;<br><span class="hljs-comment">/* 方法 */</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">mixed</span> current ( <span class="hljs-keyword">void</span> )<br><span class="hljs-keyword">public</span> <span class="hljs-keyword">mixed</span> key ( <span class="hljs-keyword">void</span> )<br><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> next ( <span class="hljs-keyword">void</span> )<br><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> rewind ( <span class="hljs-keyword">void</span> )<br><span class="hljs-keyword">public</span> <span class="hljs-keyword">mixed</span> send ( <span class="hljs-keyword">mixed</span> <span class="hljs-variable">$value</span> )<br><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-keyword">throw</span> ( <span class="hljs-built_in">Exception</span> <span class="hljs-variable">$exception</span> )<br><span class="hljs-keyword">public</span> <span class="hljs-keyword">bool</span> valid ( <span class="hljs-keyword">void</span> )<br><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> __wakeup ( <span class="hljs-keyword">void</span> )<br>&#125;<br></code></pre></td></tr></table></figure>
<h2 id="Table-of-Contents-3"><a href="#Table-of-Contents-3" class="headerlink" title="Table of Contents"></a>Table of Contents</h2><ul>
<li>Generator::current — 返回当前产生的值</li>
<li>Generator::key — 返回当前产生的键</li>
<li>Generator::next — 生成器继续执行</li>
<li>Generator::rewind — 重置迭代器</li>
<li>Generator::send — 向生成器中传入一个值</li>
<li>Generator::throw — 向生成器中抛入一个异常</li>
<li>Generator::valid — 检查迭代器是否被关闭</li>
<li>Generator::__wakeup — 序列化回调</li>
</ul>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/PHP/">PHP</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/PHP/">PHP</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客所有文章除特别声明外，均采用 <a target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2018/11/09/golang/Golang-%E4%BD%8D%E5%B7%A6%E7%A7%BB%E7%9A%84%E5%BA%94%E7%94%A8/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">『记』Golang-位左移的应用</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2018/10/30/nginx/NGINX%E5%AE%8F%E8%A7%82%E6%89%8B%E8%AE%B0/">
                        <span class="hidden-mobile">【转】NGINX宏观手记</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  

  

  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  <script  src="/js/local-search.js" ></script>



  
    <script  src="/js/img-lazyload.js" ></script>
  



  



  
    <script  src="https://cdn.jsdelivr.net/npm/tocbot@4/dist/tocbot.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4/anchor.min.js" ></script>
  
  
    <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js" ></script>
  






  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
        typing(title);
      
    })(window, document);
  </script>















<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>


</body>
</html>
